From 90f04fbb18e9a8bab838e4b12d3c9ef3e81291ef Mon Sep 17 00:00:00 2001 From: Happy-melon Date: Mon, 27 Jun 2011 19:38:30 +0000 Subject: [PATCH] Follow-up r89408, r86872: restore IContextSource and ContextSource, to be more carefully reimplemented. --- includes/AutoLoader.php | 2 + includes/RequestContext.php | 131 ++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+) diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php index f9a83f77b4..3ca3d33cd9 100644 --- a/includes/AutoLoader.php +++ b/includes/AutoLoader.php @@ -47,6 +47,7 @@ $wgAutoloadLocalClasses = array( 'ConfEditor' => 'includes/ConfEditor.php', 'ConfEditorParseError' => 'includes/ConfEditor.php', 'ConfEditorToken' => 'includes/ConfEditor.php', + 'ContextSource' => 'includes/RequestContext.php', 'Cookie' => 'includes/Cookie.php', 'CookieJar' => 'includes/Cookie.php', 'DiffHistoryBlob' => 'includes/HistoryBlob.php', @@ -115,6 +116,7 @@ $wgAutoloadLocalClasses = array( 'HTMLTextField' => 'includes/HTMLForm.php', 'Http' => 'includes/HttpFunctions.php', 'HttpRequest' => 'includes/HttpFunctions.old.php', + 'IContextSource' => 'includes/RequestContext.php', 'IcuCollation' => 'includes/Collation.php', 'ImageGallery' => 'includes/ImageGallery.php', 'ImageHistoryList' => 'includes/ImagePage.php', diff --git a/includes/RequestContext.php b/includes/RequestContext.php index 3481bb5e5e..be21c43fd5 100644 --- a/includes/RequestContext.php +++ b/includes/RequestContext.php @@ -217,3 +217,134 @@ class RequestContext { } } +/** + * Interface for objects which can provide a context on request. + */ +interface IContextSource { + + /** + * Get the WebRequest object + * + * @return WebRequest + */ + public function getRequest(); + + /** + * Get the Title object + * + * @return Title + */ + public function getTitle(); + + /** + * Get the OutputPage object + * + * @return OutputPage object + */ + public function getOutput(); + + /** + * Get the User object + * + * @return User + */ + public function getUser(); + + /** + * Get the Language object + * + * @return Language + */ + public function getLang(); + + /** + * Get the Skin object + * + * @return Skin + */ + public function getSkin(); +} + +/** + * The simplest way of implementing IContextSource is to hold a RequestContext as a + * member variable and provide accessors to it. + */ +abstract class ContextSource implements IContextSource { + + /** + * @var RequestContext + */ + private $context; + + /** + * Get the RequestContext object + * + * @return RequestContext + */ + public function getContext() { + return $this->context; + } + + /** + * Set the RequestContext object + * + * @param $context RequestContext + */ + public function setContext( RequestContext $context ) { + $this->context = $context; + } + + /** + * Get the WebRequest object + * + * @return WebRequest + */ + public function getRequest() { + return $this->context->getRequest(); + } + + /** + * Get the Title object + * + * @return Title + */ + public function getTitle() { + return $this->context->getTitle(); + } + + /** + * Get the OutputPage object + * + * @return OutputPage object + */ + public function getOutput() { + return $this->context->getOutput(); + } + + /** + * Get the User object + * + * @return User + */ + public function getUser() { + return $this->context->getUser(); + } + + /** + * Get the Language object + * + * @return Language + */ + public function getLang() { + return $this->context->getLang(); + } + + /** + * Get the Skin object + * + * @return Skin + */ + public function getSkin() { + return $this->context->getSkin(); + } +} \ No newline at end of file -- 2.20.1